import { uniqWith, xorWith } from 'lodash'

export default (state : any[] = [], action: any) => {
    switch (action.type) {
        case 'UPDATE_LOGIC_QUIZ_ITEM_ANSWERS':
            const data = [action.data].concat(state).filter(item => item)
            return uniqWith(data, (a: any, b: any) => (a.quizItemId === b.quizItemId))
        case 'SUBMIT_LOGIC_QUIZ_ITEM_ANSWERS':
            return xorWith(state, action.data, (a: any, b:any) => (a.quizItemId === b.quizItemId))
        default:
            return state
    }
}